package com.cxyd.modules.wms.dao;

import com.cxyd.common.dao.BaseDao;
import com.cxyd.modules.wms.entity.ContainerEntity;
import com.cxyd.modules.wms.entity.LocateEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 容器信息
 *
 * @author g_Cycle gengruyi01@163.com
 * @since 1.0.0 2023-04-27
 */
@Mapper
public interface ContainerDao extends BaseDao<ContainerEntity> {
    ContainerEntity getContById(Long id);

    @Select("select a.*\n" +
            "  from wms_locate a\n" +
            "\tjoin wms_container b\n" +
            "\t  on a.cont_no = b.cont_no\n" +
            "  join (select t1.cont_no,t2.spu_no\n" +
            "\t\t\t\t\tfrom wms_container_detail t1\n" +
            "\t\t\t\tleft join wms_stock t2\n" +
            "\t\t\t\t\t\ton t1.cont_locate_no = t2.cont_locate_no\n" +
            "\t\t\t\t where t2.cont_locate_no is null\n" +
            "\t\t\t\t group by t1.cont_no,t2.spu_no) c\n" +
            "\t on a.cont_no = c.cont_no\n" +
            " where a.cont_no is not null\n" +
            "   and a.active = 0\n" +
            "\t and coalesce(c.spu_no,#{spuNo}) = #{spuNo}\n" +
            "\t and b.cont_type = #{contType}\n" +
            "\t limit 1")
    LocateEntity getContOut(String spuNo,String contType,String isEmpty);
}